// load data
use data/main_file.dta, clear

// Need to add psacalc2 to adopath: https://github.com/ArthurHowardMorris/psacalc_supports_reghdfe/blob/main/psacalc2.ado 

// erase previous versions of panel A
cap erase tabs/T02_A.tex
cap erase tabs/T02_A.txt

// create panel A
reghdfe Chavismo i.HCR##i.visited [aw = log_pop],										///
		vce(cluster loc) absorb(loc i.edo##i.year)
psacalc2 delta 1.HCR#1.visited
local d = round(r(delta), .01)
outreg2 using tabs/T02_A.tex, append 													///
		keep(1.HCR#1.visited 1.HCR#1.focal 1.HCR#1.local_visited 1.HCR#1.wide_visited)	///
		addtext(Covariates, No, State-Election FE, Yes, Parish FE, Yes, Delta, `d')		
		
reghdfe Chavismo i.HCR##i.visited i.HCR##i.focal [aw = log_pop],							///
		vce(cluster loc) absorb(loc i.edo##i.year)			
psacalc2 delta 1.HCR#1.visited
local d = round(r(delta), .01)
outreg2 using tabs/T02_A.tex, append 													///
		keep(1.HCR#1.visited 1.HCR#1.focal 1.HCR#1.local_visited 1.HCR#1.wide_visited)	///
		addtext(Covariates, No, State-Election FE, Yes, Parish FE, Yes, Delta, `d')		
		
reghdfe Chavismo i.HCR##i.visited 														/// 
		i.HCR##i.focal 																	///
		i.HCR##c.log_den i.HCR##c.log_pov												///
		i.HCR##c.baseline_ch i.HCR#c.sh_urbano [aw = log_pop],							///
		vce(cluster loc) absorb(loc i.edo##i.year)			
psacalc2 delta 1.HCR#1.visited
local d = round(r(delta), .01)
outreg2 using tabs/T02_A.tex, append 													///
		keep(1.HCR#1.visited 1.HCR#1.focal 1.HCR#1.local_visited 1.HCR#1.wide_visited)	///
		addtext(Covariates, Yes, State-Election FE, Yes, Parish FE, Yes, Delta, `d')		
		
reghdfe Chavismo i.HCR##i.local_visited 												/// 
		i.HCR##i.focal 																	///
		i.HCR##c.log_den i.HCR##c.log_pov												///
		i.HCR##c.baseline_ch i.HCR#c.sh_urbano [aw = log_pop],							///
		vce(cluster loc) absorb(loc i.edo##i.year)					
psacalc2 delta 1.HCR#1.local_visited
local d = round(r(delta), .01)
outreg2 using tabs/T02_A.tex, append 													///
		keep(1.HCR#1.visited 1.HCR#1.focal 1.HCR#1.local_visited 1.HCR#1.wide_visited)	///
		addtext(Covariates, Yes, State-Election FE, Yes, Parish FE, Yes, Delta, `d')		
		
reghdfe Chavismo i.HCR##i.wide_visited 													/// 
		i.HCR##i.focal 																	///
		i.HCR##c.log_den i.HCR##c.log_pov												///
		i.HCR##c.baseline_ch i.HCR#c.sh_urbano [aw = log_pop],							///
		vce(cluster loc) absorb(loc i.edo##i.year)				
psacalc2 delta 1.HCR#1.wide_visited
local d = round(r(delta), .01)
outreg2 using tabs/T02_A.tex, append 													///
		keep(1.HCR#1.visited 1.HCR#1.focal 1.HCR#1.local_visited 1.HCR#1.wide_visited)	///
		addtext(Covariates, Yes, State-Election FE, Yes, Parish FE, Yes, Delta, `d')		

// erase previous versions of panel B
cap erase tabs/T02_B.tex
cap erase tabs/T02_B.txt

// create panel B
reghdfe Turnout i.HCR##i.visited [aw = log_pop],											///
		vce(cluster loc) absorb(loc i.edo##i.year)
psacalc2 delta 1.HCR#1.visited
local d = round(r(delta), .01)
outreg2 using tabs/T02_B.tex, append 													///
		keep(1.HCR#1.visited 1.HCR#1.focal 1.HCR#1.local_visited 1.HCR#1.wide_visited)	///
		addtext(Covariates, No, State-Election FE, Yes, Parish FE, Yes, Delta, `d')		
		
reghdfe Turnout i.HCR##i.visited i.HCR##i.focal [aw = log_pop],							///
		vce(cluster loc) absorb(loc i.edo##i.year)			
psacalc2 delta 1.HCR#1.visited
local d = round(r(delta), .01)
outreg2 using tabs/T02_B.tex, append 													///
		keep(1.HCR#1.visited 1.HCR#1.focal 1.HCR#1.local_visited 1.HCR#1.wide_visited)	///
		addtext(Covariates, No, State-Election FE, Yes, Parish FE, Yes, Delta, `d')		
		
reghdfe Turnout i.HCR##i.visited 														/// 
		i.HCR##i.focal 																	///
		i.HCR##c.log_den i.HCR##c.log_pov												///
		i.HCR##c.baseline_ch i.HCR#c.sh_urbano [aw = log_pop],							///
		vce(cluster loc) absorb(loc i.edo##i.year)			
psacalc2 delta 1.HCR#1.visited
local d = round(r(delta), .01)
outreg2 using tabs/T02_B.tex, append 													///
		keep(1.HCR#1.visited 1.HCR#1.focal 1.HCR#1.local_visited 1.HCR#1.wide_visited)	///
		addtext(Covariates, Yes, State-Election FE, Yes, Parish FE, Yes, Delta, `d')		
		
reghdfe Turnout i.HCR##i.local_visited 													/// 
		i.HCR##i.focal 																	///
		i.HCR##c.log_den i.HCR##c.log_pov												///
		i.HCR##c.baseline_ch i.HCR#c.sh_urbano [aw = log_pop],							///
		vce(cluster loc) absorb(loc i.edo##i.year)					
psacalc2 delta 1.HCR#1.local_visited
local d = round(r(delta), .01)
outreg2 using tabs/T02_B.tex, append 													///
		keep(1.HCR#1.visited 1.HCR#1.focal 1.HCR#1.local_visited 1.HCR#1.wide_visited)	///
		addtext(Covariates, Yes, State-Election FE, Yes, Parish FE, Yes, Delta, `d')
		
reghdfe Turnout i.HCR##i.wide_visited 													/// 
		i.HCR##i.focal 																	///
		i.HCR##c.log_den i.HCR##c.log_pov												///
		i.HCR##c.baseline_ch i.HCR#c.sh_urbano [aw = log_pop],							///
		vce(cluster loc) absorb(loc i.edo##i.year)				
psacalc2 delta 1.HCR#1.wide_visited
local d = round(r(delta), .01)
outreg2 using tabs/T02_B.tex, append 													///
		keep(1.HCR#1.visited 1.HCR#1.focal 1.HCR#1.local_visited 1.HCR#1.wide_visited)	///
		addtext(Covariates, Yes, State-Election FE, Yes, Parish FE, Yes, Delta, `d')	
